#include <math.h>
#include "vecmath.h"


void point_scale(point *p, float val, point *res) {
        res->x = p->x*val;
        res->y = p->y*val;
}

void point_add(point *p1, point *p2, point *res) {
        res->x = p1->x + p2->x;
        res->y = p1->y + p2->y;
}

void point_sub(point *p1, point *p2, point *res) {
        res->x = p1->x - p2->x;
        res->y = p1->y - p2->y;
}

float point_norm(point *p) {
        return sqrtf(p->x*p->x + p->y*p->y);
}

float point_dot(point *p1, point *p2) {
        return p1->x * p2->x + p1->y * p2->y;
}

void point_perp(point *p, point *res) {
        res->x = -p->y;
        res->y = p->x;
}

float point_dist(point *p1, point *p2) {
        float diff_x = p1->x - p2->x;
        float diff_y = p1->y - p2->y;

        return sqrtf(diff_x*diff_x + diff_y*diff_y);
}

